
#include "general_io_bus.h"

static void adjust(void *handle, uint16_t brightness)
{
    gpio_out_bus_handle_t *t = (gpio_out_bus_handle_t *)handle;
    hal_pin_write(&t->io, brightness>=(t->level_max/2));
}

static void init(void *handle, uint16_t level_max, uint32_t freq)
{
    gpio_out_bus_handle_t *t = (gpio_out_bus_handle_t *)handle;
    t->level_max = level_max;
}

general_out_bus_t gpio_out_bus = {
    .adjust = adjust,
    .init = init,
};

static uint8_t key_read(void *handle)
{
    gpio_key_bus_handle_t *t = (gpio_key_bus_handle_t *)handle;
    return hal_pin_read(&t->io);
}    

key_bus_t gpio_key_bus = {
    .read = key_read,
};
